﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbXRefManExt : IDisposable
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbXRefManExt(IntPtr cPtr, bool cMemoryOwn)
		{
			this.swigCMemOwn = cMemoryOwn;
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbXRefManExt obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbXRefManExt()
		{
			this.Dispose();
		}

		public virtual void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbXRefManExt(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
		}

		public static OdDbBlockTableRecord addNewXRefDefBlock(OdDbDatabase pDb, string pathName, string blockName, bool overlaid, string password, OdDbHandle handle)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDefBlock__SWIG_0(OdDbDatabase.getCPtr(pDb), pathName, blockName, overlaid, password, OdDbHandle.getCPtr(handle));
			OdDbBlockTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbBlockTableRecord addNewXRefDefBlock(OdDbDatabase pDb, string pathName, string blockName, bool overlaid, string password)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDefBlock__SWIG_1(OdDbDatabase.getCPtr(pDb), pathName, blockName, overlaid, password);
			OdDbBlockTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbBlockTableRecord addNewXRefDefBlock(OdDbDatabase pDb, string pathName, string blockName, bool overlaid)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDefBlock__SWIG_2(OdDbDatabase.getCPtr(pDb), pathName, blockName, overlaid);
			OdDbBlockTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbBlockTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbLayerTableRecord addNewXRefDependentLayer(OdDbBlockTableRecord pXRefBlock, string layerName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDependentLayer__SWIG_0(OdDbBlockTableRecord.getCPtr(pXRefBlock), layerName);
			OdDbLayerTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLayerTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLayerTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLayerTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbLayerTableRecord addNewXRefDependentLayer(OdDbObjectId xRefBlockId, string layerName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDependentLayer__SWIG_1(OdDbObjectId.getCPtr(xRefBlockId), layerName);
			OdDbLayerTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLayerTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLayerTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLayerTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbLinetypeTableRecord addNewXRefDependentLinetype(OdDbBlockTableRecord pXRefBlock, string linetypeName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDependentLinetype__SWIG_0(OdDbBlockTableRecord.getCPtr(pXRefBlock), linetypeName);
			OdDbLinetypeTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLinetypeTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLinetypeTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLinetypeTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbLinetypeTableRecord addNewXRefDependentLinetype(OdDbObjectId xRefBlockId, string linetypeName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDependentLinetype__SWIG_1(OdDbObjectId.getCPtr(xRefBlockId), linetypeName);
			OdDbLinetypeTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLinetypeTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLinetypeTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLinetypeTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbTextStyleTableRecord addNewXRefDependentTextStyle(OdDbBlockTableRecord pXRefBlock, string textStyleName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDependentTextStyle__SWIG_0(OdDbBlockTableRecord.getCPtr(pXRefBlock), textStyleName);
			OdDbTextStyleTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbTextStyleTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbTextStyleTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbTextStyleTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbTextStyleTableRecord addNewXRefDependentTextStyle(OdDbObjectId xRefBlockId, string textStyleName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbXRefManExt_addNewXRefDependentTextStyle__SWIG_1(OdDbObjectId.getCPtr(xRefBlockId), textStyleName);
			OdDbTextStyleTableRecord result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbTextStyleTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbTextStyleTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbTextStyleTableRecord)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static void addNestedXRefId(OdDbBlockTableRecord pXRefBlock, OdDbObjectId nestedBlockId)
		{
			TD_DbPINVOKE.OdDbXRefManExt_addNestedXRefId(OdDbBlockTableRecord.getCPtr(pXRefBlock), OdDbObjectId.getCPtr(nestedBlockId));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public static void getNestedXRefIds(OdDbBlockTableRecord pXRefBlock, OdDbObjectIdArray ids)
		{
			TD_DbPINVOKE.OdDbXRefManExt_getNestedXRefIds(OdDbBlockTableRecord.getCPtr(pXRefBlock), OdDbObjectIdArray.getCPtr(ids));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public static OdDbObjectId getSymbolTableRecordXrefBlockId(OdDbSymbolTableRecord pRec)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr cPtr = TD_DbPINVOKE.OdDbXRefManExt_getSymbolTableRecordXrefBlockId(OdDbSymbolTableRecord.getCPtr(pRec));
			OdDbObjectId result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbObjectId(cPtr, true));
				result = new OdDbObjectId(cPtr, false);
			}
			else
			{
				result = new OdDbObjectId(cPtr, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbXRefManExt() : this(TD_DbPINVOKE.new_OdDbXRefManExt(), true)
		{
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		protected bool swigCMemOwn;
	}
}
